<?php

namespace Api\Controller;
use Think\Controller;

class AdminController extends SuperController
{
    //插入角色权限
    public function add_jiaose(){
        $model = M('roles_menu');
        $detail = I('post.');
        $names=$detail['names'];
        $pid=$detail['pid'];
        $fcount=$model->where(['names'=>$names,'pid'=>$pid])->count();
        if($fcount){
            $data_cc['code'] = 0;
            $data_cc['msg'] = "该组这个名称已存在了";
            exit(json_encode($data_cc));
        }else{
            //查询升序数量1
            $csa=$fcount?:0 ;
            $fvdy=$csa+1;
            $data['names']=$names;
            $data['pid']=$pid;
            $data['sort']=$fvdy;
            $resault=$model->add($data);
            if($resault){
                $data_cc['code'] = 200;
                $data_cc['msg'] = "添加成功";
                exit(json_encode($data_cc));
            }else{
                $data_cc['code'] = 0;
                $data_cc['msg'] = "添加失败";
                exit(json_encode($data_cc));
            }
        }
    }
    //角色列表
    public function list_jiaose(){
        $model = M('roles_menu');
        $detail = I('post.');
        $list=$model->where(['pid'=>0])->select();
        if($list){
              foreach($list as $k=>$val){
                 $list[$k]['lsit2']=$model->where(['pid'=>$val['id']])->select();
              }
        }
        $data_cc['code'] = 200;
        $data_cc['msg'] = "查询成功";
        $data_cc['data']['list'] =$list;
        exit(json_encode($data_cc));
    }
    

}
